草庐IT

pointers - 指针问题

全部标签

docker - nginx反向代理到Golang服务器的Docker问题

我将nginx反向代理到golang服务器,每个代理都在其自己的docker容器中并正常运行。尝试连接到Go容器时,在我的本地Mac计算机和生产服务器LinuxDebian上,我都一直在Nginx中收到此错误。一周前,它在我的本地Mac机器上运行,突然之间不再可用nginx_1|2017/09/2801:29:54[error]5#5:*12upstreamtimedout(110:Connectiontimedout)whileconnectingtoupstream,client:172.23.0.1,server:,request:"GET/api/aboutHTTP/1.1",

pointers - 隐藏 nil 值,理解为什么 golang 在这里失败

我不明白如何正确确保某些东西不是nil在这种情况下:packagemaintypeshowerinterface{getWater()[]shower}typedisplaystruct{SubDisplay*display}func(ddisplay)getWater()[]shower{return[]shower{display{},d.SubDisplay}}funcmain(){//SubDisplaywillbeinitializedwithnulls:=display{}//water:=[]shower{nil}water:=s.getWater()for_,x:=ra

c - 如何从 Go 函数返回 C 指针?

我有疑问是否可以从C上的Go函数指针返回?例如main.c可以是:structopen_db_returndb_ptr=open_db(db_path);GoSlicebacket={"DB",2,2};GoSlicekey={"CONFIG",6,6};structget_value_returnval=get_value(db_ptr.r0,backet,key);close_db(db_ptr.r0);接下来是Go代码://exportopen_dbfuncopen_db(pathstring)(interface{},error){db,err:=db.Open(path,06

arrays - 我在 golang 中使用 make 方法创建二维数组时遇到问题 "panic: runtime error: index out of range"

Iamnewingolangandtrytolearnwithsmallexamples.所以我正在尝试创建一个二维数组并分配一个值,但我被困在这里任何人都可以帮助我。这是我的代码。packagemainimport("fmt")funcmain(){fmt.Println("Hello,playground")letters:=make([][]string,0,2)letters[0][0]="a"letters[0][1]="b"letters[1][0]="c"letters[1][1]="d"fmt.Println(letters)}运行这段代码时出现错误panic:runt

pointers - 在 Go 中使用类似的指针结构分配结构

我有两个相似的结构,我想将一个分配给另一个。第一个“Equipment”是用来匹配数据库的结构。第二个“JsonEquipment”是解析JSON数据的辅助结构。例子如下:typeEquipmentstruct{IDuintCategoryIDuintIpstringLoginstringPasswordstring}typeJsonEquipmentstruct{ID*uintCategory*stringIp*stringLogin*stringPassword*string}指针用于检查该字段是否存在于JSON中。更多信息:Howtorecognizevoidvalueandun

amazon-web-services - AWS Firehose 和 Go 问题

我正在尝试将一个简单的文件发送到Go中的Firehose并继续获取:panic:runtimeerror:invalidmemoryaddressornilpointerdereference[signal0xbcode=0x1addr=0x0pc=0x4015b7]goroutine1[running]:panic(0x8b9260,0xc82000a0e0)/usr/lib/go-1.6/src/runtime/panic.go:481+0x3e6main.main()/home/ubuntu/go/src/github.com/user/proj/txtParser.go:68+

function - 值接收器与指针接收器

我很不清楚在哪种情况下我想使用值接收器而不是总是使用指针接收器。从文档中回顾一下:typeTstruct{aint}func(tvT)Mv(aint)int{return0}//valuereceiverfunc(tp*T)Mp(ffloat32)float32{return1}//pointerreceiver文档还说“对于基本类型、slice和小型结构等类型,值接收器非常便宜,因此除非方法的语义需要指针,否则值接收器是高效的清晰。”第一点他们的文档说值接收器“非常便宜”,但问题是它是否比指针接收器便宜。所以我做了一个小基准(codeongist)这告诉我,即使对于只有一个字符串字段

go - 在 Windows 7 上通过 cgo 安装使用 SDL2 的包时出现问题

我在使用VisualStudioCode为golang安装SDL2时遇到问题。我尝试获取包裹:"C:\Users\Bob\go\src\flappyGopher>goget-vgithub.com/veandco/go-sdl2/sdlgithub.com/veandco/go-sdl2/sdl#github.com/veandco/go-sdl2/sdlInfileincludedfrom..\github.com\veandco\go-sdl2\sdl\audio.go:4:0:./sdl_wrapper.h:2:23:fatalerror:SDL2/SDL.h:Nosuchfil

mongodb - Bson接口(interface)有一些问题

我使用带有mgo(gopkg.in/mgo.v2)包的MongoDBv3.6.4贝森varidinterface{}id=249678041972736bson.M{"_id":id}varidint64id=249678041972736bson.M{"_id":id}两个bson不一样?例如:funcGetUser(idinterface{})(*User,error){session:=MongoDB()defersession.Close()varm*Usererr:=session.DB.C("user").Find(&bson.M{"_id":id}).One(&m)//!

html - Buffalo v0.11.0 与 flash 和 application.html 有问题吗?

我是Golang和Buffalo的初学者。我正在尝试使用https://github.com/gobuffalo/authrecipe中的authrecipe创建密码身份验证服务.但是,在尝试使用buffalodev运行它时,我从JSON转储中收到以下错误:ERRO[2018-05-10T14:20:48-04:00]application.html:line14:_flash.html:第3行:flash:未知标识符content_type=text/htmldb="0s"duration="5.354757ms"human_size="0B"method=GETparams="{}